package IOStreamStudy.objectInputStream;

/**
 * 反序列化(将数据类型和数据的值,转换为对象)
 * 要注意转换的类型要以一对应,int型对应int型,顺序不对会导致乱码
 * 这里要注意一个向下转型的问题,要让dog类让序列化和反序列化的类都能访问到,否则无法完成向下转型
 * */
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class objectInputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu" +
                "\\IOStreamStudy\\objectOutputStream\\objectData.dat";
        FileInputStream fileInputStream = new FileInputStream(filePath);
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        System.out.println(objectInputStream.readInt());
        System.out.println(objectInputStream.readChar());
        System.out.println(objectInputStream.readBoolean());
        System.out.println(objectInputStream.readDouble());
        System.out.println(objectInputStream.readFloat());
        System.out.println(objectInputStream.readUTF());
        Object dog = objectInputStream.readObject();
        System.out.println(dog);// 这里要注意一个向下转型的问题,要让dog类让序列化和反序列化的类都能访问到,否则无法完成向下转型

        objectInputStream.close();
    }
}
